import { BroadCastCall } from "../broadCast/BroadCastCall";
import { MessageBlock } from "../../../../Framework/MQ/MessageBlock";
import { SSeqAttributeUpdate } from "../../../../Message/Public/SSeqAttributeUpdate";
import { CallLater } from "../../../common/net/CallLater";
import { NetDispatcher } from "../../../mvc/core/NetDispatcher";
import { ServerCommand } from "../../mvc/ServerCommand";
import { SAttributeUpdate } from "../../../../Message/Public/SAttributeUpdate";
import { ConstConfig } from "../../resource/ConstConfig";
import { EEntityAttribute } from "../../../../Message/Public/EEntityAttribute";
import { Language } from "../../../../extend/language/Language";
import { MsgManager } from "../../manager/MsgManager";
import { DateParser } from "../../../common/tools/DateParser";
import { ClockManager } from "../../manager/ClockManager";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { UpdateCode } from "../../../component/gconst/UpdateCode";
import { AttributeValue } from "../../scene/player/AttributeValue";
import { AttributeTextType } from "../../scene/player/type/AttributeTextType";
import { Cache } from "../../cache/Cache";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { EPrictUnit } from "../../../../Message/Public/EPrictUnit";
type int = number;
//class MoneyUpdateCommand
    
    export  class MoneyUpdateCommand extends BroadCastCall
    {
        constructor(arg1: Object)
        {
            super(arg1);
            return;
        }

        public /* override */ call(arg1: MessageBlock): void
        {
            var loc2=null;
            var loc1=arg1.messageBase as SSeqAttributeUpdate;
            var loc3=0;
            var loc4=loc1.updates;
            for(loc2 of loc4) 
            {
                this.moneyUpdate(loc2, loc1.code);
                this._isMoneyUpdate = true;
            }
            if (this._isMoneyUpdate) 
            {
                CallLater.addCallBack(this.onMoneyUpdateHandler);
                this._isMoneyUpdate = false;
            }
            return;
        }

        /* internal  */onMoneyUpdateHandler(): void
        {
            NetDispatcher.dispatchCmd(ServerCommand.MoneyUpdate, _cache.role.money);
            this._isMoneyUpdate = true;
            return;
        }

        /* internal  */moneyUpdate(arg1: SAttributeUpdate, arg2: int): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=0;
            var loc7=0;
            var loc8=null;
            var loc9=0;
            var loc10=null;
            var loc11=0;
            var loc12=0;
            var loc13=null;
            var loc14=0;
            var loc15=null;
            var loc16=0;
            var loc17=null;
            var loc18=0;
            var loc19=null;
            var loc20=0;
            var loc21=null;
            var loc22=0;
            var loc23=null;
            var loc24=0;
            var loc25=null;
            var loc26=0;
            var loc27=null;
            var loc28=0;
            var loc29=null;
            var loc30=0;
            var loc31=null;
            var loc32=null;
            var loc1=ConstConfig.instance.getOutUpdateStrByCode(arg2);
            var loc5="";
            var loc6="";
            var loc33=arg1.attribute.__value;
            switch (loc33) 
            {
                case EEntityAttribute._EAttributeWarehouseGold:
                {
                    loc7 = arg1.value - _cache.role.money.warehouseGold;
                    _cache.role.money.warehouseGold = arg1.value;
                    _cache.role.money.gold = _cache.role.money.gold - loc7;
                    if ((loc8 = Language.getString(40102)) != "") 
                    {
                        MsgManager.showRollTipsMsg(loc8);
                    }
                    break;
                }
                case EEntityAttribute._EAttributeWarehouseCoin:
                {
                    loc9 = arg1.value - _cache.role.money.warehouseCoin;
                    _cache.role.money.warehouseCoin = arg1.value;
                    _cache.role.money.coin = _cache.role.money.coin - loc9;
                    loc10 = Language.getString(40102);
                    if (loc8 != "") 
                    {
                        MsgManager.showRollTipsMsg(loc10);
                    }
                    break;
                }
                case EEntityAttribute._EAttributeCoin:
                {
                    loc11 = arg1.value - _cache.role.money.coin;
                    loc12 = arg1.value - _cache.role.money.coin;
                    _cache.role.money.coin = arg1.value;
                    loc13 = "";
                    if (loc11 > 0) 
                    {
                        loc13 = Language.getStringByParam(90025, loc11.toString());
                    }
                    else if (loc11 < 0) 
                    {
                        loc13 = Language.getStringByParam(90026, Math.abs(loc11).toString());
                    }
                    if (loc13 != "") 
                    {
                        MsgManager.addTipText(loc13);
                    }
                    if (!(loc1 == "") && !(loc11 == 0)) 
                    {
                        loc2 = Language.getStringByParam(43800, DateParser.parse(ClockManager.instance.nowDate, "hh: mm: ss") + " " + loc1 + Math.abs(loc11).toString());
                        Dispatcher.dispatchEvent(new DataEvent(EventName.WalletMoneyUpdate, loc2));
                    }
                    if (arg2 == UpdateCode.EUpdateCodeByKillBoss && _cache.guild.isInSelfManorMap()) 
                    {
                        NetDispatcher.dispatchCmd(ServerCommand.RoleSingleAttributeChange, new AttributeValue(AttributeTextType.coin, true, loc11));
                    }
                    break;
                }
                case EEntityAttribute._EAttributeCoinBind:
                {
                    loc14 = arg1.value - _cache.role.money.coinBind;
                    _cache.role.money.coinBind = arg1.value;
                    loc15 = "";
                    if (loc14 > 0) 
                    {
                        loc15 = Language.getStringByParam(90027, loc14.toString());
                    }
                    else if (loc14 < 0) 
                    {
                        loc15 = Language.getStringByParam(90028, Math.abs(loc14).toString());
                    }
                    if (loc15 != "") 
                    {
                        MsgManager.addTipText(loc15);
                    }
                    if (!(loc1 == "") && !(loc14 == 0)) 
                    {
                        loc2 = Language.getStringByParam(43801, DateParser.parse(ClockManager.instance.nowDate, "hh: mm: ss") + " " + loc1 + Math.abs(loc14).toString());
                        Dispatcher.dispatchEvent(new DataEvent(EventName.WalletMoneyUpdate, loc2));
                    }
                    if (arg2 != UpdateCode.EUpdateCodeGuildTreeRipe) 
                    {
                        if (arg2 != UpdateCode.EUpdateCodeFreeDeletegate) 
                        {
                            if (arg2 == UpdateCode.EUpdateCodeCountryMoney) 
                            {
                                NetDispatcher.dispatchCmd(ServerCommand.RoleSingleAttributeChange, new AttributeValue(AttributeTextType.coinBind, true, loc14));
                            }
                        }
                        else 
                        {
                            NetDispatcher.dispatchCmd(ServerCommand.DelegateCoinCopyReward, loc14);
                        }
                    }
                    else 
                    {
                        NetDispatcher.dispatchCmd(ServerCommand.RoleSingleAttributeChange, new AttributeValue(AttributeTextType.coinBind, true, loc14));
                        NetDispatcher.dispatchCmd(ServerCommand.GuildTreeCoinBindAddCommand, loc14);
                    }
                    break;
                }
                case EEntityAttribute._EAttributeGold:
                {
                    loc16 = arg1.value - _cache.role.money.gold;
                    _cache.role.money.gold = arg1.value;
                    loc17 = "";
                    if (loc16 > 0) 
                    {
                        loc17 = Language.getStringByParam(90029, loc16.toString());
                    }
                    else if (loc16 < 0) 
                    {
                        loc17 = Language.getStringByParam(90030, Math.abs(loc16).toString());
                    }
                    if (loc17 != "") 
                    {
                        MsgManager.addTipText(loc17);
                    }
                    if (!(loc1 == "") && !(loc16 == 0)) 
                    {
                        loc2 = Language.getStringByParam(43802, DateParser.parse(ClockManager.instance.nowDate, "hh: mm: ss") + " " + loc1 + Math.abs(loc16).toString());
                        Dispatcher.dispatchEvent(new DataEvent(EventName.WalletMoneyUpdate, loc2));
                    }
                    break;
                }
                case EEntityAttribute._EAttributeGoldBind:
                {
                    loc18 = arg1.value - _cache.role.money.goldBind;
                    _cache.role.money.goldBind = arg1.value;
                    loc19 = "";
                    if (loc18 > 0) 
                    {
                        loc19 = Language.getStringByParam(90031, loc18.toString());
                        NetDispatcher.dispatchCmd(ServerCommand.FlyBindGoldCommand, null);
                    }
                    else if (loc18 < 0) 
                    {
                        loc19 = Language.getStringByParam(90032, Math.abs(loc18).toString());
                    }
                    if (loc19 != "") 
                    {
                        MsgManager.addTipText(loc19);
                        if (arg2 == UpdateCode.EUpdateCodeGuildPartyFood) 
                        {
                            NetDispatcher.dispatchCmd(ServerCommand.RoleSingleAttributeChange, new AttributeValue(AttributeTextType.goldBind, true, loc18));
                        }
                        if (arg2 == UpdateCode.EUpdateCodeByKillBoss && Cache.instance.guild.isInSelfManorMap()) 
                        {
                            NetDispatcher.dispatchCmd(ServerCommand.RoleSingleAttributeChange, new AttributeValue(AttributeTextType.goldBind, true, loc18));
                        }
                    }
                    if (!(loc1 == "") && !(loc18 == 0)) 
                    {
                        loc2 = Language.getStringByParam(43803, DateParser.parse(ClockManager.instance.nowDate, "hh: mm: ss") + " " + loc1 + Math.abs(loc18).toString());
                        Dispatcher.dispatchEvent(new DataEvent(EventName.WalletMoneyUpdate, loc2));
                    }
                    break;
                }
                case EEntityAttribute._EAttributeHonour:
                {
                    loc20 = arg1.value - _cache.role.money.honour;
                    _cache.role.money.honour = arg1.value;
                    loc21 = "";
                    if (loc20 > 0) 
                    {
                        loc21 = Language.getStringByParam(90033, loc20.toString());
                    }
                    else if (loc20 < 0) 
                    {
                        loc21 = Language.getStringByParam(90034, Math.abs(loc20).toString());
                    }
                    if (loc21 != "") 
                    {
                        MsgManager.addTipText(loc21);
                    }
                    break;
                }
                case EEntityAttribute._EAttributeArena:
                {
                    loc22 = arg1.value - _cache.role.money.arena;
                    _cache.role.money.arena = arg1.value;
                    loc23 = "";
                    if (loc22 > 0) 
                    {
                        loc23 = Language.getStringByParam(90035, loc22.toString());
                    }
                    else if (loc22 < 0) 
                    {
                        loc23 = Language.getStringByParam(90036, Math.abs(loc22).toString());
                    }
                    if (loc21 != "") 
                    {
                        MsgManager.addTipText(loc23);
                    }
                    break;
                }
                case EEntityAttribute._EAttributePoint:
                {
                    loc24 = arg1.value - _cache.role.money.point;
                    _cache.role.money.point = arg1.value;
                    loc25 = "";
                    if (loc24 > 0) 
                    {
                        loc25 = Language.getStringByParam(90037, loc24.toString());
                    }
                    else if (loc24 < 0) 
                    {
                        loc25 = Language.getStringByParam(90038, Math.abs(loc24).toString());
                    }
                    if (loc25 != "") 
                    {
                        MsgManager.addTipText(loc25);
                    }
                    break;
                }
                case EEntityAttribute._EAttributeContributionAdd:
                {
                    if (arg2 != UpdateCode.EUpdateCodeGuildTreeWorm) 
                    {
                        if (arg2 != UpdateCode.EUpdateCodeGuildStruggle) 
                        {
                            if (arg2 != UpdateCode.EUpdateCodeByKillBoss) 
                            {
                                if (arg2 != UpdateCode.EUpdateCodeGuildDefense) 
                                {
                                    if (arg2 == UpdateCode.EUpdateCodeGuildPartyFood || arg2 == UpdateCode.EUpdateCodeGuildParty) 
                                    {
                                        Dispatcher.dispatchEvent(new DataEvent(EventName.GuildPartyContriAdd, arg1.value));
                                    }
                                }
                                else 
                                {
                                    Dispatcher.dispatchEvent(new DataEvent(EventName.GuildDefenseUpdateContribute, arg1.value));
                                }
                            }
                            else 
                            {
                                Dispatcher.dispatchEvent(new DataEvent(EventName.GuildContrubuteAddByKillBoss, arg1.value));
                            }
                        }
                        else 
                        {
                            _cache.copy.guildCopyContribution = _cache.copy.guildCopyContribution + arg1.value;
                            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildCopyUpdateContribute, arg1.value));
                        }
                    }
                    else 
                    {
                        NetDispatcher.dispatchCmd(ServerCommand.GuildPartyContributeAddCommand, arg1.value);
                    }
                    break;
                }
                case EEntityAttribute._EAttributeInterHonour:
                {
                    loc26 = arg1.value - _cache.role.money.interHonour;
                    _cache.role.money.interHonour = arg1.value;
                    loc27 = "";
                    if (loc26 > 0) 
                    {
                        loc27 = Language.getStringByParam(30196, loc26);
                    }
                    else if (loc26 < 0) 
                    {
                        loc27 = Language.getStringByParam(30197, Math.abs(loc26));
                    }
                    if (loc27 != "") 
                    {
                        MsgManager.addTipText(loc27);
                    }
                    break;
                }
                case EEntityAttribute._EAttributeWuxingEnergyValue:
                {
                    if (arg1.value != -1) 
                    {
                        loc28 = arg1.value - _cache.role.wuxingInfo.juhunValue;
                        _cache.role.updateJuHunValue(arg1.value);
                        loc29 = "";
                        if (loc28 > 0) 
                        {
                            loc29 = Language.getStringByParam(26356, loc28);
                            Dispatcher.dispatchEvent(new DataEvent(EventName.WuXingValueAdd, loc28));
                        }
                        else if (loc28 < 0) 
                        {
                            loc29 = Language.getStringByParam(26357, Math.abs(loc28));
                        }
                        if (loc29 != "") 
                        {
                            MsgManager.addTipText(loc29);
                        }
                        NetDispatcher.dispatchCmd(ServerCommand.WuXingDiceUpdateCommand, _cache.role.wuxingInfo.wxDice);
                    }
                    break;
                }
                case EEntityAttribute._EAttributePrestige:
                {
                    loc30 = arg1.value - _cache.role.money.prestige;
                    _cache.role.money.prestige = arg1.value;
                    loc31 = "";
                    if (loc30 > 0) 
                    {
                        loc31 = Language.getStringByParam(80059, loc30.toString());
                    }
                    if (loc31 != "") 
                    {
                        MsgManager.addTipText(loc31);
                    }
                    NetDispatcher.dispatchCmd(ServerCommand.AchievementAchievementValueUpdate, {});
                    break;
                }
                case EEntityAttribute._EAttributePetCoin:
                {
                    loc4 = arg1.value - _cache.role.money.petCoin;
                    _cache.role.money.petCoin = arg1.value;
                    loc5 = "";
                    if (loc4 > 0) 
                    {
                        loc5 = Language.getStringByParam(54683, loc4);
                    }
                    else if (loc4 < 0) 
                    {
                        loc5 = Language.getStringByParam(54684, Math.abs(loc4));
                    }
                    MsgManager.addTipText(loc5);
                    NetDispatcher.dispatchCmd(ServerCommand.PetCpnPetCoinCommand, arg1.value);
                    break;
                }
                case EEntityAttribute._EAttributeMagicStone:
                {
                    loc4 = arg1.value - _cache.role.money.magicStone;
                    _cache.role.money.magicStone = arg1.value;
                    loc5 = "";
                    if (loc4 > 0) 
                    {
                        loc5 = Language.getStringByParam(44410, loc4);
                    }
                    else if (loc4 < 0) 
                    {
                        loc5 = Language.getStringByParam(44411, Math.abs(loc4));
                    }
                    MsgManager.addTipText(loc5);
                    NetDispatcher.dispatchCmd(ServerCommand.GangfightMagicStoneCommand, arg1.value);
                    break;
                }
                case EEntityAttribute._EAttributeMerit:
                {
                    loc4 = arg1.value - _cache.role.money.merit;
                    _cache.role.money.merit = arg1.value;
                    loc5 = "";
                    if (loc4 > 0) 
                    {
                        loc5 = Language.getStringByParam(44412, loc4);
                    }
                    else if (loc4 < 0) 
                    {
                        loc5 = Language.getStringByParam(44413, Math.abs(loc4));
                    }
                    MsgManager.addTipText(loc5);
                    NetDispatcher.dispatchCmd(ServerCommand.GangfightMeritCommand, arg1.value);
                    break;
                }
                case EEntityAttribute._EAttributeBrokenSoul:
                {
                    loc32 = GameDefConfig.instance.getEPrictUnitName(EPrictUnit._EPriceUnitBrokenSoul);
                    loc4 = arg1.value - _cache.role.money.brokenSoul;
                    _cache.role.money.brokenSoul = arg1.value;
                    loc5 = "";
                    if (loc4 > 0) 
                    {
                        loc5 = Language.getStringByParam(11131, loc4, loc32);
                    }
                    else if (loc4 < 0) 
                    {
                        loc5 = Language.getStringByParam(11132, Math.abs(loc4), loc32);
                    }
                    MsgManager.addTipText(loc5);
                    NetDispatcher.dispatchCmd(ServerCommand.PetMingBrokenSoulUpdate, loc4);
                    break;
                }
                case EEntityAttribute._EAttributeIntegralOne:
                {
                    loc6 = GameDefConfig.instance.getEPrictUnitName(EPrictUnit._EPriceUnitIntegralOne);
                    loc4 = arg1.value - _cache.role.money.integralOne;
                    _cache.role.money.integralOne = arg1.value;
                    this.showUpdateMsg(loc4, loc6);
                    break;
                }
                case EEntityAttribute._EAttributeIntegralTwo:
                {
                    loc6 = GameDefConfig.instance.getEPrictUnitName(EPrictUnit._EPriceUnitIntegralTwo);
                    loc4 = arg1.value - _cache.role.money.integralTwo;
                    _cache.role.money.integralTwo = arg1.value;
                    this.showUpdateMsg(loc4, loc6);
                    break;
                }
                case EEntityAttribute._EAttributeIntegralThree:
                {
                    loc6 = GameDefConfig.instance.getEPrictUnitName(EPrictUnit._EPriceUnitIntegralThree);
                    loc4 = arg1.value - _cache.role.money.integralThree;
                    _cache.role.money.integralThree = arg1.value;
                    this.showUpdateMsg(loc4, loc6);
                    break;
                }
                case EEntityAttribute._EAttributeCountryContribution:
                {
                    loc6 = GameDefConfig.instance.getEPrictUnitName(EPrictUnit._EPriceUnitCountryContribution);
                    loc4 = arg1.value - _cache.role.money.countryContribution;
                    _cache.role.money.countryContribution = arg1.value;
                    this.showUpdateMsg(loc4, loc6);
                    NetDispatcher.dispatchCmd(ServerCommand.CountryContributionUpdate, arg1.value);
                    NetDispatcher.dispatchCmd(ServerCommand.RoleSingleAttributeChange, new AttributeValue(AttributeTextType.countryContribution, true, loc4));
                    break;
                }
                case EEntityAttribute._EAttributeRobFlagHonour:
                {
                    loc6 = GameDefConfig.instance.getEPrictUnitName(EPrictUnit._EPriceUnitRobFlagHonour);
                    loc4 = arg1.value - _cache.role.money.robFlagHonour;
                    _cache.role.money.robFlagHonour = arg1.value;
                    this.showUpdateMsg(loc4, loc6);
                    NetDispatcher.dispatchCmd(ServerCommand.RobFlagContributionUpdate, arg1.value);
                    NetDispatcher.dispatchCmd(ServerCommand.RoleSingleAttributeChange, new AttributeValue(AttributeTextType.robFlagCountribution, true, loc4));
                    break;
                }
                case EEntityAttribute._EAttributeRobIslandCoin:
                {
                    loc6 = GameDefConfig.instance.getEPrictUnitName(EPrictUnit._EPriceUnitRobIslandCoin);
                    loc4 = arg1.value - _cache.role.money.robIslandCoin;
                    _cache.role.money.robIslandCoin = arg1.value;
                    this.showUpdateMsg(loc4, loc6);
                    break;
                }
                case EEntityAttribute._EAttributeSpiritCoin:
                {
                    loc6 = GameDefConfig.instance.getEPrictUnitName(EPrictUnit._EPriceUnitSpiritCoin);
                    loc4 = arg1.value - _cache.role.money.spiritCoin;
                    _cache.role.money.spiritCoin = arg1.value;
                    this.showUpdateMsg(loc4, loc6);
                    break;
                }
                case EEntityAttribute._EAttributeLadderCoin:
                {
                    loc6 = GameDefConfig.instance.getEPrictUnitName(EPrictUnit._EPriceUnitLadder);
                    loc4 = arg1.value - _cache.role.money.ladderCoin;
                    _cache.role.money.ladderCoin = arg1.value;
                    this.showUpdateMsg(loc4, loc6);
                    break;
                }
                case EEntityAttribute._EAttributeArenaCrossCoin:
                {
                    loc6 = GameDefConfig.instance.getEPrictUnitName(EPrictUnit._EPriceUnitArenaCrossCoin);
                    loc4 = arg1.value - _cache.role.money.arenaCrossCoin;
                    _cache.role.money.arenaCrossCoin = arg1.value;
                    this.showUpdateMsg(loc4, loc6);
                    break;
                }
                case EEntityAttribute._EAttributeDominionCoin:
                {
                    loc6 = GameDefConfig.instance.getEPrictUnitName(EPrictUnit._EPriceUnitDominion);
                    loc4 = arg1.value - _cache.role.money.dominionCoin;
                    _cache.role.money.dominionCoin = arg1.value;
                    this.showUpdateMsg(loc4, loc6);
                    break;
                }
            }
            return;
        }

        /* internal  */showUpdateMsg(arg1: int, arg2: string): void
        {
            var loc1="";
            if (arg1 > 0) 
            {
                loc1 = Language.getStringByParam(90301, arg1, arg2);
            }
            else if (arg1 < 0) 
            {
                loc1 = Language.getStringByParam(90302, Math.abs(arg1), arg2);
            }
            MsgManager.addTipText(loc1);
            MsgManager.showRollTipsMsg(loc1);
            return;
        }

        private /* var */_isMoneyUpdate: Boolean=false;
    }
